package d4_collection_set;

import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * 2024/6/5 TreeSet Cjj 8：58
 */
public class SetTree4 {
    public static void main(String[] args) {
        //treeSet 默认按照升序排序 不可重复 无索引
        Set<Integer> treeSet = new TreeSet<>();
        treeSet.add(1);
        treeSet.add(3);
        treeSet.add(2);
        treeSet.add(2);
        treeSet.add(6);
        System.out.println(treeSet);


        //就近原则 按照身高排序
/*       Set<Student> students = new TreeSet<>(new Comparator<Student>() {
           @Override
           public int compare(Student o1, Student o2) {
               return Double.compare(o1.getHeight(),o2.getHeight());
           }
       });*/


        Set<Student> students = new TreeSet<>((o1,o2)->Double.compare(o1.getHeight(),o2.getHeight()));
       students.add(new Student("蜘蛛精",23,169.7));
       students.add(new Student("紫霞",22,169.8));
       students.add(new Student("至尊宝",22,159.8));
       students.add(new Student("牛魔王",27,134.3));
        System.out.println(students);
    }
}
